package com.ymatou.iapi.sellercs.testcase;

import java.io.IOException;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellercs.parameter.UpdateLastLastActiveTimeBean;
import com.ymatou.iapi.sellercs.service.UpdateLastLastActiveTimeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.database.model.YmtOnlinecs;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
/**
*更新最后活跃时间
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateLastLastActiveTime{
	private static UpdateLastLastActiveTimeBean updatelastlastactivetimeBean;
	private static UpdateLastLastActiveTimeCall updatelastlastactivetimeCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static String sellername = EnvSetup.getData("autotest_sellerName1");
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新最后活跃时间");
	}

	@Before
	public void caseUp() throws ClientProtocolException, IOException {
		updatelastlastactivetimeBean=new UpdateLastLastActiveTimeBean();
		updatelastlastactivetimeCall=new UpdateLastLastActiveTimeCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
		 SellerCSIMCallService.OffLine(sellerId, null);
		SellerCSIMCallService.OffLine(zsellerId, null);
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updatelastlastactivetimeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateLastLastActiveTime_001() {
		Logger.start(true,"更新最后活跃时间成功");
		try {
			SellerCSIMCallService.AppLogin(sellerId);
			List<YmtOnlinecs> ol = YmtSellerCSIMWapper.selectYmtOnlinecs(sellerId, sellerId);
			Long t1=0l;
			if(!(ol==null||ol.isEmpty())){
				t1=ol.get(0).getLastActiveTime().getTime();
			}
			Thread.sleep(3000);
			updatelastlastactivetimeBean.setCSId(sellerId);
			updatelastlastactivetimeCall.setData(updatelastlastactivetimeBean);
			updatelastlastactivetimeCall.callService();		
			Logger.verifyEquals("200", updatelastlastactivetimeCall.getString("Status"), "验证Status");
			Thread.sleep(1000);
			Long t2=YmtSellerCSIMWapper.selectYmtOnlinecs(sellerId, sellerId).get(0).getLastActiveTime().getTime();
			Logger.verifyNotEquals(t1, t2, "验证时间变更");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UpdateLastLastActiveTime_002() {
		Logger.start(true,"不输入csid失败");
		try {
			updatelastlastactivetimeCall.setData(updatelastlastactivetimeBean);
			updatelastlastactivetimeCall.callService();		
			Logger.verifyEquals("400", updatelastlastactivetimeCall.getString("Status"), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}